package scanpackage.inbound;


import io.netty.channel.ChannelHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import scanpackage.filter.HeaderHttpRequestFilter;
import scanpackage.filter.HttpRequestFilter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.util.ReferenceCountUtil;
import scanpackage.outbound.HttpOutboundHandler;
import scanpackage.property.RouteProperty;
@ChannelHandler.Sharable
@Service
public class HttpInboundHandler extends ChannelInboundHandlerAdapter {
    @Autowired
    private HttpOutboundHandler handler;

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) {
        ctx.flush();
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        try {
            FullHttpRequest fullRequest = (FullHttpRequest) msg;
            handler.handle(fullRequest, ctx,"");
        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            ReferenceCountUtil.release(msg);
        }
    }



}
